package com.kai.mqtt.controller;

import com.kai.mqtt.data.PageResult;
import com.kai.mqtt.data.Result;
import com.kai.mqtt.data.request.PageRetainMessageRequest;
import com.kai.mqtt.data.response.RetainMessageResponse;
import com.kai.mqtt.message.service.IRetainMessageService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author weijk
 * @since 2024/7/6
 */
@RestController
@RequestMapping("/retain")
public class RetainController {

    @Resource
    private IRetainMessageService retainMessageService;

    /**
     * 分页查询保留消息列表
     *
     * @param request 参数
     * @return 保留消息列表
     */
    @PostMapping("/page")
    public PageResult<RetainMessageResponse> pageRetain(@RequestBody PageRetainMessageRequest request) {
        return retainMessageService.pageRetain(request);
    }

    /**
     * 删除保留消息
     *
     * @param topic 主题
     * @return true-成功，false-失败
     */
    @DeleteMapping("/delete")
    public Result<Boolean> deleteRetain(@RequestParam("topic") String topic) {
        return Result.success(retainMessageService.deleteRetain(topic));
    }
}
